package com.ry.novel.controller;

import com.ry.novel.model.dto.UserInfo;
import com.ry.novel.utils.JwtTokenUtil;
import org.apache.commons.lang3.StringUtils;
import org.mockito.internal.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;

/**
 * @author ry
 * @since 2022-01-22 20:59
 **/
public class BaseController {

    @Autowired
    protected JwtTokenUtil jwtTokenUtil;



    protected String getToken(HttpServletRequest request){
        return request.getHeader("Authorization");
    }

    protected UserInfo getUserInfo(HttpServletRequest request){
        String token = getToken(request);
        if (StringUtils.isBlank(token)){
            //为空直接返回null
            return null;
        }else {
            return jwtTokenUtil.getUserInfoFromToken(token);
        }
    }
}
